package app.v1.wdt.service;

import app.v1.wdt.domain.event.SalesOrderDetailsGroupByShopStatisticsEvent;
import app.v1.wdt.domain.event.SalesOrderDetailsGroupByShopWarehouseStatisticsEvent;
import app.v1.wdt.domain.vo.GroupByShopNoAndSpecNoVo;
import org.springframework.context.event.EventListener;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * wdt销售订单细节服务
 * @author feizns
 * @since 2023/07/19
 */
public interface WdtSalesOrderDetailsService {

    /**
     * 从qm wdt拉出销售订单细节
     * @param startDate 开始日期
     * @param endDate 结束日期
     */
    default void pullSalesOrderDetailsFromQmWdt(LocalDate startDate, LocalDate endDate) {
        pullSalesOrderDetailsFromQmWdt(startDate.atStartOfDay(), endDate.atStartOfDay());
    }

    /**
     * 从qm wdt拉出销售订单细节
     * @param date 日期
     */
    default void pullSalesOrderDetailsFromQmWdt(LocalDate date) {
        pullSalesOrderDetailsFromQmWdt(date.atStartOfDay(), date.plusDays(1).atStartOfDay());
    }

    /**
     * 从qm wdt拉出销售订单细节
     * @param startTime 开始时间
     * @param endTime 结束时间
     */
    void pullSalesOrderDetailsFromQmWdt(LocalDateTime startTime, LocalDateTime endTime);

    /**
     * 统计销售订单细节
     * @param startDate 开始日期
     * @param endDate 结束日期
     */
    default void statisticsSalesOrderDetails(LocalDate startDate, LocalDate endDate) {
        while ( startDate.isBefore(endDate) ) {
            statisticsSalesOrderDetails(startDate);
            startDate = startDate.plusDays(1);
        }
    }

    /**
     * 删除指定日期销售单
     * @param date {@link LocalDate}
     */
    void deleteSalesOrderDetails(LocalDate date);

    /**
     * 统计销售订单细节
     * @param date 日期
     */
    void statisticsSalesOrderDetails(LocalDate date);

    /**
     * 统计销售订单细节
     * @param date 日期
     */
    void statisticsSalesOrderDetails(LocalDate date, String shopNo, String warehouseNo);

    /**
     * 统计销售订单细节
     * @param vos vos
     */
    void statisticsSalesOrderDetails(List<GroupByShopNoAndSpecNoVo> vos);

    /**
     * 根据订单编号计数
     * @param orderNo 订单没有
     * @return long
     */
    long countingByOrderNo(String orderNo);

    /**
     * 按订单不存在
     * @param orderNo 订单没有
     * @return long
     */
    default boolean existsByOrderNo(String orderNo) {
        return countingByOrderNo(orderNo) > 0;
    }

    /**
     * 处理销售订单细节发送到宜搭对销货单店铺和商品统计
     * @param event 事件
     */
    @EventListener
    void handleSalesOrderDetailsSendToYiDaShopAndSpecNoGroupStatistics(SalesOrderDetailsGroupByShopStatisticsEvent event);

    /**
     * 调度员销售订单细节商店和仓库组统计事件
     * @param event 事件
     */
    @EventListener
    void dispatcherSalesOrderDetailsShopAndWarehouseGroupStatisticsEvent(SalesOrderDetailsGroupByShopStatisticsEvent event);

    /**
     * 处理销售订单细节发送到易达商店和仓库组统计信息
     * @param event 事件
     */
    @EventListener
    void handleSalesOrderDetailsSendToYiDaShopAndWarehouseGroupStatistics(SalesOrderDetailsGroupByShopWarehouseStatisticsEvent event);

    /**
     * 处理销售订单细节发送到商店和仓库组统计信息
     * @param event 事件
     */
    @EventListener
    void handleSalesOrderDetailsSendToCjtShopAndWarehouseGroupStatistics(SalesOrderDetailsGroupByShopWarehouseStatisticsEvent event);

}
